// Declare the TaskManager Developers namespace.
TaskManager.Developers = {}

// Initialize the developers view.
TaskManager.Developers.init = function() {
	TaskManager.DataAccess.getDevelopers(function(developers) {
		// Initialize the developers listview.
		$("#developers-listview").empty().kendoMobileListView({
			dataSource: kendo.data.DataSource.create({
				data: developers
			}),
			template: kendo.template($("#developers-listview-template").html())
		});
	});
}



// Declare the TaskManager Developer namespace.
TaskManager.Developer = {}

TaskManager.Developer.show = function(e) {
	var developer = TaskManager.DataAccess.getDeveloper(e.view.params.id);
	
	$("#developer-id").val(e.view.params.id);
	
	$("#developer-firstname").val(developer.FirstName);
	$("#developer-lastname").val(developer.LastName);
}

TaskManager.Developer.save = function() {
	try {
		var id = $("#developer-id").val();
		var developer = TaskManager.DataAccess.getDeveloper(id);

		developer.FirstName = $("#developer-firstname").val();
		developer.LastName = $("#developer-lastname").val();
		
		TaskManager.DataAccess.saveDeveloper(developer, function(response) {
			if (response.result.length == 0) {
				TaskManager.Developers.init();

				TaskManager.Developer.results(true, "Green", "Save Complete");

				// After 2 seconds, hide the message.
				setTimeout('$("#developer-save-results").fadeOut("slow", function() { TaskManager.Developer.results(false); });', 2000);
			}
		});
	} catch (err) {
	}
}

TaskManager.Developer.results = function(show, color, message) {
	var $results = $("#developer-save-results");
	
	if (show) {
		$results.css("display", "").css("position", "").css("color", color).text(message);
	} else {
		$results.css("display", "none").css("position", "absolute").text("");
	}
}